// #ifndef DYNAMICCHART_H
// #define DYNAMICCHART_H
#pragma once

#include <QWidget>
#include <QtCharts>
#include <QTimer>
#include <QScopedPointer>
#include "reactionmodel.h"

QT_CHARTS_BEGIN_NAMESPACE
    class QLineSeries;

    class QValueAxis;
QT_CHARTS_END_NAMESPACE

QT_CHARTS_USE_NAMESPACE

class DynamicChartView : public QChartView {
Q_OBJECT

public:
    explicit DynamicChartView(QWidget *parent = nullptr);

    ~DynamicChartView() override = default;

public slots:

    void startTimer();

    void stopTimer();

private:
    // 智能指针
    QScopedPointer<QChart> chart;
    QScopedPointer<QLineSeries> series;
    // x轴可以为数值/时间坐标轴
    // QScopedPointer<QDateTimeAxis> axisX;
    QScopedPointer<QValueAxis> axisX;
    QScopedPointer<QValueAxis> axisY;
    // 定时器
    QTimer seriesTimer;
    // 间隔数值宽度, 当前点的x y
    qreal scrollStep, curPointX, curPointY;
    // QDate baseDate;
    ReactionModel model;

    // 定时触发
    void handleTimeout();

    // 每添加一次x++
    void addPoint(qreal y);
};

// #endif // DYNAMICCHART_H
